package com.wy2cloud.authorize.controller;

import java.security.Principal;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.oauth2.provider.AuthorizationRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

/**
 * 自定义 /oauth/confirm_access 页面
 * @author wuyy<16349023@qq.com>,nnsword
 * @date 2018年4月10日下午5:42:22
 *
 */
@Controller  
@SessionAttributes("authorizationRequest")  
public class OAuth2ApprovalController {  
    
  private final static Logger logger=LoggerFactory.getLogger(OAuth2ApprovalController.class);
  
  @RequestMapping("/oauth/confirm_access")  
  public String getAccessConfirmation(Map<String, Object> model, HttpServletRequest request,Principal principal)  
      throws Exception {  
      @SuppressWarnings("unchecked")
      Map<String, String> scopes = (Map<String, String>) (model.containsKey("scopes") ? model.get("scopes") : request
              .getAttribute("scopes"));
      Map<String, String[]> parameters = request.getParameterMap();
      
      AuthorizationRequest authorizationRequest= (AuthorizationRequest) model.get("authorizationRequest");
      model.put("clientScopes", scopes);
      
      String userName= principal.getName();
      model.put("userName", userName);
      //logger.info("request.parameters:{}",parameters);
      //logger.info("principal:{}",principal);
    return "confirm_access";
  }  
  
}  